package com.sbeam.controller;


import com.sbeam.service.ImageService;
import com.sbeam.vo.ImageVo;
import com.sbeam.vo.SysResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/images")
public class ImagesController {

    @Autowired
    private ImageService imageService;

    @PostMapping("/saveImages")
    public SysResult saveImages(MultipartFile file){
        ImageVo imageVo = imageService.upload(file);
        System.out.println(imageVo);
        if (imageVo != null){
            return SysResult.success(imageVo);
        }
        return SysResult.failed();
    }

    @DeleteMapping("/deleteImage")
    public SysResult deleteImage(String virtualPath){
        if (imageService.deleteImage(virtualPath)){
            return SysResult.success();
        }
        return SysResult.failed();
    }

}
